/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package TestCase.wide;

import classgenerator.logic.FieldType;
import classgenerator.logic.Oracle;
import classgenerator.logic.OracleImpl;
import deadCodeRmv.StartMeDCR;
import java.util.ArrayList;
import takatuka.classreader.dataObjs.ClassFile;
import takatuka.classreader.dataObjs.MethodInfo;
import takatuka.classreader.dataObjs.Un;
import takatuka.classreader.logic.constants.FieldTypes;
import takatuka.classreader.logic.constants.JavaInstructionsOpcodes;
import takatuka.classreader.logic.factory.FactoryFacade;
import takatuka.classreader.logic.factory.FactoryPlaceholder;

/**
 *
 * @author irfan
 */
public class WideTestCase extends StartMeDCR {

    public static void main(String args[]) throws Exception {
        new WideTestCase().start(args);
    }

    @Override
    public void execute(String args[]) throws Exception {
        Oracle oracle = new OracleImpl();
        FactoryFacade factoryFacade = FactoryPlaceholder.getInstanceOf().getFactory();
        ClassFile cFile = oracle.createEmptyClassFile("WideTestCase", "WideTestCase.java");



        MethodInfo constrMethodInfo = oracle.addDefaultConstructor(cFile);


        int defaultConstrRefInfo = oracle.addMethodRefInCP(cFile, cFile.getThisClass().intValueSigned(),
                oracle.getUTF8FromCP(cFile, constrMethodInfo.getNameIndex().intValueSigned()),
                oracle.getUTF8FromCP(cFile, constrMethodInfo.getDescriptorIndex().intValueSigned()));

        /**
         * added the main method in the class file without any code
         */
        MethodInfo mainMethod = oracle.addMainFunction(cFile);

        /**
         * IConst_1
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.ICONST_1, mainMethod.getCodeAtt()));


        /**
         * Wide
         *
         */
        Un operand = factoryFacade.createUn(0x36).trim(1);
        operand.conCat(factoryFacade.createUn(0x0100).trim(2));
        Un operand1 = factoryFacade.createUn(0x15).trim(1);
        operand1.conCat(factoryFacade.createUn(0x0100).trim(2));
        mainMethod.getCodeAtt().setMaxLocals(300);
        mainMethod.getCodeAtt().setMaxStack(2);
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.WIDE,
                operand, mainMethod.getCodeAtt()));
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.WIDE,
                operand1, mainMethod.getCodeAtt()));








        /**
         * return
         */
        oracle.addInstruction(cFile, mainMethod, factoryFacade.createInstruction(JavaInstructionsOpcodes.RETURN, mainMethod.getCodeAtt()));

//        super.execute(args);


    }
}
